import { http } from "@/utils/http/axios";

export default class BaseApi<T> {
  private preUrl;

  constructor(preUrl: string) {
    this.preUrl = preUrl;
  }

  listEntityByCondition = (condition: T) => {
    // console.log("cui api tset111111111111111111");
    // console.log(this.preUrl + "/search");
    // console.log(condition);
    return http.request({
      url: this.preUrl + "/search",
      method: "POST",
      data: condition,
    });
  };

  insertEntity(data: T) {
    return http.request({
      url: this.preUrl + "/save",
      method: "POST",
      data: data,
    });
  }

  editEntity(id: number, data: T) {
    return http.request({
      url: this.preUrl + `/update/${id}`,
      method: "PUT",
      data: data,
    });
  }

  deleteEntityById(ids: number[]) {
    return http.request({
      url: this.preUrl + "/batch-delete",
      method: "post",
      data: ids,
    });
  }
}
